package com.xin.beauty.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xin.beauty.pojo.entity.Doctor;
import com.xin.beauty.mapper.DoctorMapper;
import com.xin.beauty.pojo.entity.Project;
import com.xin.beauty.pojo.query.DoctorQuery;
import com.xin.beauty.pojo.vo.DoctorCountVO;
import com.xin.beauty.service.IDoctorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Xin
 * @since 2025-04-14
 */
@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements IDoctorService {
    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public IPage<Doctor> list(DoctorQuery doctorQuery) {
        IPage<Doctor> page = new Page<>(doctorQuery.getPage(), doctorQuery.getLimit());
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!ObjectUtils.isEmpty(doctorQuery.getName()), "name", doctorQuery.getName());
        queryWrapper.like(!ObjectUtils.isEmpty(doctorQuery.getPhone()), "phone", doctorQuery.getPhone());
        queryWrapper.between(!ObjectUtils.isEmpty(doctorQuery.getBeginUpdateTime()) && !ObjectUtils.isEmpty(doctorQuery.getEndUpdateTime()),
                "update_time", doctorQuery.getBeginUpdateTime(), doctorQuery.getEndUpdateTime());
        doctorMapper.selectPage(page, queryWrapper);
        return page;
    }

    @Override
    public List<DoctorCountVO> selectDoctorCount() {
        return doctorMapper.selectDoctorCount();
    }

    @Override
    public List<Doctor> listNotAll() {
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq( "status", 1);
        List<Doctor> doctorList = doctorMapper.selectList(queryWrapper);
        return doctorList;
    }

}
